WEBAPP['pageHomeBum'] = function() {
//	$('.tab-loads').click();
};

$.fn.isSearchBox = function() {
	var ENGINES = {
		web : {
			form : 'http://www.google.com.vn/search?hl=vi',
			text : 'q'
		},
		images : {
			form : 'http://www.google.com.vn/search?tbm=isch&hl=vi&biw=1280&bih=649&source=hp',
			text : 'q'
		},
		video : {
			form : 'http://www.youtube.com/results?',
			text : 'search_query'
		},
		dict : {
			form : 'http://translate.google.com.vn/?tl=vi',
			text : 'text'
		},
		news : {
			form : 'http://news.google.com.vn/news/search?pz=1&cf=all&hl=vi&top=n',
			text : 'q'
		},
		mp3 : {
			form : 'http://mp3.zing.vn/tim-kiem/bai-hat.html?',
			text : 'q'
		},
		map : {
			form : 'http://maps.google.com/maps?hl=vi',
			text : 'q'
		},
		ask : {
			form : 'http://www.google.com.vn/giaidap/search',
			text : 'q'
		},
	};
	return this.each(function() {
		$(this).find('.box-search-tab a').on('click touch', function() {
			var T = $(this).parent().find('.cur').removeClass('cur').end().end().addClass('cur');

			var searchType = T.attr('search');
			var engine = ENGINES[searchType];
			$('#searchGroupForm').attr('action', engine['form']).find('#searchGroupText').attr('name', engine['text']);

			return false;
		});
	});
};

$(document).ready(function() {
	$('#searchBox').isSearchBox().find('.box-search-tab a:first').click();

	// parseX();
});

function parseX() {
	var bw = function(html, startToken, endToken) {
		var start = html.indexOf(startToken);
		if (start > -1) {
			start += startToken.length;
		}

		var end = html.indexOf(endToken, start);
		return html.substring(start, end);
	};

	var text = $('#siteText').val().replace(/class="end "/g).replace(/class="catehide"/g);
	var parts = text.split('<li><a target="_blank" ');
	$.each(parts, function(i, part) {
		if (i > 0) {
			console.log(part + "\n\n");

			var cat = bw(part, 'href="/', '"');
			var name = bw(part, 'class="w_title ', '<span');
			console.log(cat, name);

		}

	});
}